import Vue from "vue";

// 查询混入
const CommonFilter = {
  mounted() {
    this.$initFilterVal()
  },
  watch: {
    'form.timer'(v) {
      if (v && v.length) {
        this.form.startTime = v[0]
        this.form.endTime = v[1]
      }else{
        this.form.startTime = null
        this.form.endTime = null
      }
      delete this.form.timer
    }
  },
  methods: {
    $handleSearch() {
      this.$refs.baseTable.queryparams.pageIndex = 1;
      this.$refs.baseTable.queryparams = {
        pageIndex: 1,
        pageSize: 10,
        userId: 0
      };

      this.$refs.baseTable.queryparams = {
        ...this.form,
        ...this.$refs.baseTable.queryparams,
      };
      this.$refs.baseTable.initData();
    },
    $handleRest() {
      for (var _key in this.form) {
        this.form[_key] = "";
      }
      this.$handleSearch();
      for (var _key in this.$refs) {
        if (this.$refs[_key] && this.$refs[_key].value) {
          this.$refs[_key].clear();
        }
      }
    },
    // 默认值过滤、
    $initFilterVal() {
      for (var _key in this.form) {
        if (this.$refs && this.$refs[_key]) {
          this.$refs[_key].value = this.form[_key]
        }
      }
    }
  }
};

export default CommonFilter;
